import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class CardDome {
    //确定初始牌的花色
    private static final String [] SUITS ={"♣","♠","♥","♦"};
     //buyDeck方法 生成牌的数量 类型是Card
    public static List<Card> buyDeck() {
        List<Card> list =new ArrayList<>();
        for (int i = 0; i < SUITS.length; i++) {
            //每个SUITS的下标生成13张牌
            for (int j = 1; j <= 13; j++) {
                String suit = SUITS[i];
                int rank = j;
                Card card = new Card(rank,suit);
                //
                list.add(card);
            }
        }
        return list;
    }
    private static void shuffe(List<Card> list){
        //Random(); 创建一个新的随机数生成器
        Random random =new Random();
        for (int i = list.size()-1; i >0 ; i--) {
            //确定随机范围random.nextInt(i)
            int t = random.nextInt(i);
            //创建一个替换的方法来打乱牌库
            swap(list,i,t);
        }
    }
    //创建一个变更的方法来打乱牌库
    private static void swap(List<Card> list, int i, int j){
        Card n = list.get(i);
        list.set(i,list.get(j));
        list.set(j,n);
    }

    public static void main(String[] args) {

       List<Card> list =buyDeck();
        System.out.println(list);
        shuffe(list);
        System.out.println(list);
        List< List<Card>> hand =new ArrayList<>();

        List<Card> hand1 =new ArrayList<>();
        List<Card> hand2 =new ArrayList<>();
        List<Card> hand3 =new ArrayList<>();
        hand.add(hand1);
        hand.add(hand2);
        hand.add(hand3);


        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 3; j++) {
                Card card = list.remove(0);
                    hand.get(j).add(card);
            }
        }

        System.out.println(hand.get(0));
        System.out.println(hand.get(1));
        System.out.println(hand.get(2));
        System.out.println(list);
    }

}
